package controller.record;

import pojo.account.Reader;
import pojo.view.RRecord;
import service.RecordService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "RGetRecordController", value = "/RGetRecordController")
public class RGetRecordController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Reader reader = (Reader) request.getSession().getAttribute("reader");
        RecordService service = new RecordService();
        // get unused
        RRecord unUsedRecord = service.getUnUsedById(reader.getId());
        // get in use
        RRecord inUseRecord = service.getInUseById(reader.getId());
        // get completed records
        List<RRecord> completedRecords = service.getCompletedById(reader.getId());

        request.setAttribute("unUsedRecord", unUsedRecord);
        request.setAttribute("inUseRecord", inUseRecord);
        request.setAttribute("completedRecords", completedRecords);

        request.getRequestDispatcher("/view/reader/record/record.jsp").forward(request, response);
    }
}
